﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using ShareIt_MVC3.Models;
using System.Configuration.Provider;
using System.Collections;


namespace ShareIt_MVC3
{
    /// <summary>
    /// Diese Klasse stellt verschiedene Rollen zur verfügung und macht eine Unterscheidung zwischen Admin und Benutzer möglich.
    /// </summary>
    public class ShareItRoleProvider : RoleProvider
    {

        private UserCollection userColl = new UserCollection();

        /// <summary>
        ///  hinzufügen eines Benutzers zu einer Rolle
        /// </summary>
        /// <param name="usernames"></param>
        /// <param name="roleNames"></param>
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        //Eine neue Rolle erstellen
        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        //Löschen einer Rolle
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetRolesForUser(string username)
        {
            List<String> roles = new List<String>();

            if (username == null || username == "")
                throw new ProviderException("User name cannot be empty or null.");

            User user = userColl.GetUserByUsername(username);
            if (user.IsAdmin)
                roles.Add("Admin");

            return roles.ToArray();
        
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            User user = userColl.GetUserByUsername(username);
            return user.IsAdmin;
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}